package com.ecommerce.product.entity;

import jakarta.persistence.*;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 产品实体
 */
@Data
@Entity
@Table(name = "t_product")
@EntityListeners(AuditingEntityListener.class)
public class Product {

    /**
     * 产品ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;

    /**
     * 产品名称
     */
    @Column(nullable = false, length = 100)
    private String name;

    /**
     * 产品描述
     */
    @Column(length = 500)
    private String description;

    /**
     * 产品价格
     */
    @Column(nullable = false, precision = 10, scale = 2)
    private BigDecimal price;

    /**
     * 库存数量
     */
    @Column(nullable = false)
    private Integer stock;

    /**
     * 分类ID
     */
    @Column(name = "category_id")
    private Long categoryId;

    /**
     * 产品图片URL
     */
    @Column(name = "image_url")
    private String imageUrl;

    /**
     * 销量
     */
    @Column(name = "sales", nullable = false)
    private Integer sales = 0;
}